home *** CD-ROM | disk | FTP | other *** search
- /* 4567890123456789012345678901234567890123456789012345678901234567 */
- #include <Windows.h>
- #include <LowMem.h>
- #include <Folders.h>
- #include <Errors.h>
-
- #if STRICT_WINDOWS
- OSErr ZoomWindowToTrash(WindowRef aWindow);
- void GetWindowRect(WindowRef aWindow, Rect *aRect);
- #else
- OSErr ZoomWindowToTrash(WindowPtr aWindow);
- void GetWindowRect(WindowPtr aWindow, Rect *aRect);
- #endif
- void UpdateDesktop(void);
- OSErr GetTrashIconRect(Rect *aRect);
- OSErr OpenGrayRgnPort(GrafPtr *aGrayRgnPort,
- GrafPtr *aCurrentPort, RgnHandle *aClip);
- void ZoomBetweenRects(Rect *aStartingRect, Rect *anEndingRect,
- short aCount);
- void CloseGrayRgnPort(GrafPtr aGrayRgnPort,
- GrafPtr aCurrentPort, RgnHandle aClip);
-
- #define kNumBetween 20
- #define kCountDelay 1
-
- #if STRICT_WINDOWS
- OSErr ZoomWindowToTrash(WindowRef aWindow) {
- #else
- OSErr ZoomWindowToTrash(WindowPtr aWindow) {
- #endif
- OSErr theError = noErr;
- Rect theStartingRect, theEndingRect;
- GrafPtr theCurrentPort, theGrayRgnPort;
- RgnHandle theCurrentClip;
-
- HideWindow(aWindow);
- UpdateDesktop();
- GetPort(&theCurrentPort);
- #if STRICT_WINDOWS
- SetPortWindowPort(aWindow);
- #else
- SetPort(aWindow);
- #endif
- GetWindowRect(aWindow, &theStartingRect);
- theError = GetTrashIconRect(&theEndingRect);
- if (theError == noErr) {
- SetPort(theCurrentPort);
- theError = OpenGrayRgnPort(&theGrayRgnPort, &theCurrentPort,
- &theCurrentClip);
- }
- if (theError == noErr) {
- ZoomBetweenRects(&theStartingRect, &theEndingRect,
- kNumBetween);
- CloseGrayRgnPort(theGrayRgnPort, theCurrentPort,
- theCurrentClip);
- }
- return theError;
- }
-
- void UpdateDesktop(void) {
- EventRecord theEvent;
- (void)WaitNextEvent(0, &theEvent, 10, nil);
- }
-
- #if STRICT_WINDOWS
- void GetWindowRect(WindowRef aWindow, Rect *aRect) {
- #else
- void GetWindowRect(WindowPtr aWindow, Rect *aRect) {
- #endif
- GrafPtr theCurrentPort;
- Point thePoint;
-
- GetPort(&theCurrentPort);
- #if STRICT_WINDOWS
- SetPortWindowPort(aWindow);
- thePoint.v = GetWindowPort(aWindow)->portRect.top;
- thePoint.h = GetWindowPort(aWindow)->portRect.left;
- #else
- SetPort(aWindow);
- thePoint.v = aWindow->portRect.top;
- thePoint.h = aWindow->portRect.left;
- #endif
- LocalToGlobal(&thePoint);
- (*aRect).top = thePoint.v;
- (*aRect).left = thePoint.h;
- #if STRICT_WINDOWS
- thePoint.v = GetWindowPort(aWindow)->portRect.bottom;
- thePoint.h = GetWindowPort(aWindow)->portRect.right;
- #else
- thePoint.v = aWindow->portRect.bottom;
- thePoint.h = aWindow->portRect.right;
- #endif
- LocalToGlobal(&thePoint);
- (*aRect).bottom = thePoint.v;
- (*aRect).right = thePoint.h;
- SetPort(theCurrentPort);
- }
-
- OSErr GetTrashIconRect(Rect *aRect) {
- OSErr theError;
- short theVRefNum;
- long theDirID;
- Str255 theName;
- CInfoPBRec pb;
- Point thePoint;
-
- theError = FindFolder(kOnSystemDisk, kTrashFolderType,
- kDontCreateFolder, &theVRefNum, &theDirID);
- if (theError == fnfErr) {
- theError = FindFolder(kOnSystemDisk,
- kWhereToEmptyTrashFolderType, kDontCreateFolder,
- &theVRefNum, &theDirID);
- }
- if (theError == noErr) {
- pb.dirInfo.ioNamePtr = theName;
- pb.dirInfo.ioVRefNum = theVRefNum;
- pb.dirInfo.ioDrDirID = theDirID;
- pb.dirInfo.ioFDirIndex = -1; /* use ioDrDirID */
- theError = PBGetCatInfoSync(&pb);
- if (theError == noErr) {
- thePoint.v = pb.dirInfo.ioDrUsrWds.frLocation.v;
- thePoint.h = pb.dirInfo.ioDrUsrWds.frLocation.h;
- LocalToGlobal(&thePoint);
- aRect->top = thePoint.v;
- aRect->left = thePoint.h;
- aRect->bottom = aRect->top + 32;
- aRect->right = aRect->left + 32;
- }
- }
- return theError;
- }
-
- OSErr OpenGrayRgnPort(GrafPtr *aGrayRgnPort, GrafPtr *aCurrentPort,
- RgnHandle *aClip) {
- OSErr theError = noErr;
- RgnHandle theGrayRgn = LMGetGrayRgn();
-
- GetPort(aCurrentPort);
- *aGrayRgnPort = (GrafPtr)NewPtrClear(sizeof(GrafPort));
- if (*aGrayRgnPort != nil) {
- OpenPort(*aGrayRgnPort);
- CopyRgn(theGrayRgn, (*aGrayRgnPort)->visRgn);
- theError = MemError();
- if (theError == noErr) {
- (*aGrayRgnPort)->portRect = (**theGrayRgn).rgnBBox;
- *aClip = NewRgn();
- if (*aClip != nil) {
- GetClip(*aClip);
- } else {
- theError = MemError();
- }
- }
- } else {
- theError = MemError();
- }
- return theError;
- }
-
- void CloseGrayRgnPort(GrafPtr aGrayRgnPort, GrafPtr aCurrentPort,
- RgnHandle aClip) {
- SetClip(aClip);
- DisposeRgn(aClip);
- ClosePort(aGrayRgnPort);
- SetPort(aCurrentPort);
- }
-
- void ZoomBetweenRects(Rect *aStartingRect, Rect *anEndingRect,
- short aCount) {
- short top, left, bottom, right, count;
- Rect theRect = *aStartingRect;
- long theTicks;
-
- PenPat(&qd.gray);
- PenMode(patXor);
- top = (anEndingRect->top - aStartingRect->top) / (aCount + 1);
- left = (anEndingRect->left - aStartingRect->left) / (aCount + 1);
- bottom =
- (anEndingRect->bottom - aStartingRect->bottom) / (aCount + 1);
- right =
- (anEndingRect->right - aStartingRect->right) / (aCount + 1);
-
- for (count=0; count<(aCount+2); count ++) {
- FrameRect(&theRect);
- Delay(kCountDelay, &theTicks);
- FrameRect(&theRect);
- theRect.top += top;
- theRect.left += left;
- theRect.bottom += bottom;
- theRect.right += right;
- }
- }
-